package shayu.search.controller;

import io.renren.common.to.es.SkuEsModel;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shayu.search.exception.BizCodeEume;
import shayu.search.service.ProductSaveService;

import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping(value = "/search/save")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    @RequestMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelList) {
        boolean status=false;
        try {
            status = productSaveService.productStatusUp(skuEsModelList);
        } catch (IOException e) {
            //log.error("商品上架错误{}",e);

            return R.error(BizCodeEume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEume.PRODUCT_UP_EXCEPTION.getMsg());
        }

        if(status){
            return R.error(BizCodeEume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEume.PRODUCT_UP_EXCEPTION.getMsg());
        }else {
            return R.ok();
        }

    }

}
